package smashedapples.twitter.vo
{
	import smashedapples.core.ValueObject;
	import smashedapples.utils.RegExUtils;

	[Bindable]
	dynamic public class TweetVO extends ValueObject
	{
		public function TweetVO( data:Object = null )
		{
			super( data );
		}

		public var created_at:Date;

		public var favorited:Boolean;

		public var id:Number;

		public var in_reply_to_screen_name:String;

		public var in_reply_to_status_id:Number;

		public var in_reply_user_id:Number

		public var source:String;

		public var text:String = "";

		public var truncated:Boolean = false;

		public var user:TwitterUserVO;


		[Bindable( "textChanged" )]
		public function htmlText():String
		{
			var t:String = this.text;
			var urls:Array = this.text.match( RegExUtils.getUrlPattern());

			var href:String;

			for each( var url:String in urls )
			{
				href = "<u><a href='event:" + url + "'>" + url + "</a></u>";
				t = t.replace( url, href );
			}

			var usernames:Array = this.text.match( RegExUtils.getTwitterUsernamePattern());

			for each( var username:String in usernames )
			{
				href = "<u><a href='event:" + username + "'>" + username + "</a></u>";
				t = t.replace( username, href );
			}

			return t;
		}

		public function setCreated_at( value:Object ):void
		{

			//this.created_at = new Date( Date( Date.parse( value as String );
			//trace( value );
			//trace( Date.parse( value as String ) );
			//var d:Date = new Date();
			//		d.setMilliseconds( Date.parse( value as String ) );
			//	trace( d );

		}

		public function setUser( value:Object ):void
		{
			this.user = new TwitterUserVO( value );
		}


	}
}